﻿using System;
using Core.Library;
using DataObject;
using DataObject.Adv;

namespace CMS.Controls.Adv
{
    public partial class Banner : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                ListAdvByTypeId();
        }

        private void ListAdvByTypeId()
        {
            var o = AdvController.Adv_GetAdvSingle();
            if (o != null)
                ltAdvSingle.Text = string.Format("<center><a href=\"{0}\"><img src=\"/Thumb.ashx?Id={1}&tId={2}&Size=700\" class=\"pt10 pb10\" alt=\"\"/></a></center>", o.Url, o.AdvId, (int)CategoryType.Adv);
        }  

        protected void BtnSaveSingle(object sender, EventArgs e)
        {
            AdvController.Adv_DeleteByType((int)AdvType.Single);

            var o = new AdvObject();
            o.TypeId    = (int)AdvType.Single;
            o.Priority  = 1;
            o.ImagePath = txtImage.Text;
            o.Url       = txtUrl.Text;
            AdvController.Adv_Create(o);

            ListAdvByTypeId();
            ltMessage.Text = MessageUtility.ShowMessage(null, "Cập nhật Banner thành công.", MessageType.Information); 
        }
    }
}